import { useMenuStore } from '@/stores/menu'
/**
 *
 */
export const myPlugin = {
    install(app: any, options: any) {
        //封装全局组件、全局指令、全局...
        //v-permession
        app.directive('permession', (el: any, binding: any) => {
            const menuStore = useMenuStore()
            // 这会在 `mounted` 和 `updated` 时都调用
            // 1. 获取当前角色资源列表 [AddProduct,EditProduct...]
            const resourceList = menuStore.resourceList
            // 2. 按钮绑定的权限值 binding.value
            const value = binding.value
            if (value && Array.isArray(value) && value.length > 0) {
                const isHide = resourceList.some(item => value.includes(item))

                if (!isHide) {
                    el && el.remove()
                } else {
                    console.log(
                        'need rols! Like v-perisson =["AddUser","EditUser"]'
                    )
                }
            }
        })
    },
}
